﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinaer.Model.Common;
using Chinaer.Core.Helper;

namespace Chinaer.Bll
{
    public class CustomerCaoZuo : Repository, IBll.ICustomerCaoZuo
    {
        private static CustomerCaoZuo _customerCaoZuo = null;
        public static CustomerCaoZuo Instance
        {
            get
            {
                if (_customerCaoZuo == null)
                {
                    _customerCaoZuo = new CustomerCaoZuo();
                }
                return _customerCaoZuo;
            }
            set
            {
                _customerCaoZuo = value;
            }
        }
        private Chinaer.IDao.ICustomer_CaoZuoDAO customerCaoZuoDAO = new Chinaer.Dao.CustomerCaoZuoDAO();
        public JsonResult Add(DTO.Customer_CaoZuoDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_Customer_CaoZuo model_CustomerCaoZuo = new Model.Entities.Model_Customer_CaoZuo();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_CustomerCaoZuo);
            if (string.IsNullOrEmpty(model_CustomerCaoZuo.ID) || model_CustomerCaoZuo.ID.Trim() == "")
            {
                model_CustomerCaoZuo.ID = Chinaer.Core.Helper.GenerateIDHelper.GenerateID();
            }
            jsonResult.Success = customerCaoZuoDAO.Add(model_CustomerCaoZuo);
            return jsonResult;
        }

        public JsonResult Delete(DTO.Customer_CaoZuoDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_Customer_CaoZuo model_CustomerCaoZuo = new Model.Entities.Model_Customer_CaoZuo();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_CustomerCaoZuo);
            jsonResult.Success = customerCaoZuoDAO.Delete(model_CustomerCaoZuo);
            return jsonResult;
        }

        public JsonResult Delete(string id)
        {
            JsonResult jsonResult = new JsonResult();
            jsonResult.Success = customerCaoZuoDAO.Delete(id);
            return jsonResult;
        }

        public JsonResult Update(DTO.Customer_CaoZuoDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_Customer_CaoZuo model_CustomerCaoZuo = new Model.Entities.Model_Customer_CaoZuo();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_CustomerCaoZuo);
            jsonResult.Success = customerCaoZuoDAO.Update(model_CustomerCaoZuo);
            return jsonResult;
        }

        public DTO.Customer_CaoZuoDTO GetByID(string id)
        {
            Model.Entities.Model_Customer_CaoZuo model_CustomerCaoZuo = new Model.Entities.Model_Customer_CaoZuo();
            DTO.Customer_CaoZuoDTO customerCaoZuoDTO = new DTO.Customer_CaoZuoDTO();
            model_CustomerCaoZuo = customerCaoZuoDAO.GetByID(id);
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(model_CustomerCaoZuo, customerCaoZuoDTO);
            return customerCaoZuoDTO;
        }
    }
}
